fix(cudnn): implement cuDNN 9 error codes, replace todo!() panic with proper mapping#371
Open
CharryWu wants to merge 2 commits intoRust-GPU:mainfrom
Open
fix(cudnn): implement cuDNN 9 error codes, replace todo!() panic with proper mapping#371CharryWu wants to merge 2 commits intoRust-GPU:mainfrom
CharryWu wants to merge 2 commits intoRust-GPU:mainfrom
Conversation
…r mapping cuDNN 9 restructured cudnnStatus_t into a hierarchical numeric system (2xxx=BAD_PARAM, 3xxx=NOT_SUPPORTED, 4xxx=INTERNAL_ERROR, 5xxx=EXECUTION_FAILED) and removed several codes present in cuDNN 8. Changes: - Add four new CudnnError variants behind #[cfg(cudnn9)]: SublibraryVersionMismatch, SerializationVersionMismatch, Deprecated, SublibraryLoadingFailed - Replace the _ => todo!() wildcard in IntoResult::into_result() with a category-based fallback that maps cuDNN 9 sub-codes (e.g. BAD_PARAM_NULL_POINTER) to their parent category variant using integer division, eliminating the runtime panic entirely - Add wire both new variants in into_raw() for round-trip correctness Verified against cudnn_graph.h from cuDNN 9.20 (anaconda distribution). The cudnn crate itself compiles cleanly; only pre-existing cust bindgen errors prevent a full cargo check -p cudnn from succeeding. Made-with: Cursor
a5216d2 to
268981e
Compare
frjnn
approved these changes
Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a runtime process panic in
crates/cudnn/src/error.rsthat occurs when the crate is compiled against cuDNN 9+. The wildcard arm_ => todo!()inIntoResult::into_result()would abort the process whenever cuDNN returned any of the new hierarchical sub-codes introduced in cuDNN 9. This PR replaces it with a proper category-based fallback mapping.Problem
Background: how cuDNN version detection works
At compile time, the build script reads the cuDNN version from the linker metadata and emits a
cfgflag:That part works fine. The bug lives entirely in the runtime code that the cfg selection activates.
The broken runtime path (before this PR)
cuDNN 9 restructured
cudnnStatus_tinto a hierarchical numeric system. Each broad error category was split into specific sub-codes that share the same thousands-digit as their parent:The old
into_result()only matched the parent codes exactly. Any unrecognised sub-code fell into the wildcard arm:Fix
Runtime path after this PR
Round-trip correctness (
CudnnError ↔ cudnnStatus_t)into_raw()is also updated so the new variants can be converted back to their raw status codes, keepinginto_raw(into_result(x)) == xfor the new named variants:Changes
crates/cudnn/src/error.rsCudnnErrorvariants behind#[cfg(cudnn9)]; replace_ => todo!()with category-based fallback; wire variants ininto_raw(); add unit testsNew
CudnnErrorvariants (cuDNN 9 only):SublibraryVersionMismatch— sub-library version mismatchSerializationVersionMismatch— serialisation version mismatchDeprecated— deprecated API calledSublibraryLoadingFailed— required sub-library could not be loadedRemoved:
_ => todo!()wildcard panic — replaced with deterministic integer-division fallbackNew unit tests:
Unit tests in
crates/cudnn/src/error.rs— no GPU needed, run withcargo test -p cudnn:success_maps_to_okCUDNN_STATUS_SUCCESS→Ok(())common_status_codes_mapCudnnErrorvariantcudnn8_only_status_codes_mapAllocFailed,ArchMismatch, …) gated behind#[cfg(not(cudnn9))]cudnn9_named_status_codes_mapcudnn9_hierarchical_subcodes_map_to_parent_categoryBAD_PARAM_NULL_POINTER(2002) andNOT_SUPPORTED_SHAPE(3xxx) map to their parent category instead of panickingcudnn9_into_raw_round_trips_for_named_errorsCudnnError → into_raw() → into_result()round-trip for cuDNN 9 variantsinto_raw_round_trips_for_common_errorsinto_raw_round_trips_for_cudnn8_only_errorsRun tests with
cargo test -p cudnn -- --nocaptureVerification
cudnn_graph.hfrom cuDNN 9.20 (CUDA 13.2, Anaconda distribution on Windows 11)cudnncrate compiles cleanly in this configurationTesting
cudnncrate compiles with cuDNN 9.20 on Windows 11 / CUDA 13.2todo!()remains in the#[cfg(cudnn9)]error-handling path#[cfg(not(cudnn9))]into_raw()for round-trip correctness